/*
 * QTXpost - a Qt-based blog client.
 * Copyright (C) 2010 Helen Sommer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program (in COPYING); if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA  02111-1307  USA
 *
 * The project is hosted on http://code.google.com/p/qtxpost
 */

#include "Preview.h"

Preview::Preview(QWidget *parent) 
  : QDialog(parent)
{
  QVBoxLayout *layout = new QVBoxLayout();
  setLayout(layout);
  QLabel *label = new QLabel(tr("Preview"));
  layout->addWidget(label); 

  content = new QWebView(this);
  content->setMinimumWidth(400);
  layout->addWidget(content);

  QWebPage *page = content->page();
  page->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
  
  QPushButton *close = new QPushButton(tr("&Close"), this);
  close->setMaximumWidth(100);
  connect(close, SIGNAL(clicked()), this, SLOT(close()));
  connect(content, SIGNAL(linkClicked(const QUrl &)), this, SLOT(linkView(const QUrl &)));
  
  layout->addWidget(close);
}

void Preview::linkView(const QUrl & url)
{
  QDesktopServices::openUrl(url);
}

void Preview::setText(QString text)
{
  content->setHtml(text);
}
